    var address ;
	var member = $api.getStorage('member');
    apiready = function () {
    	var header = $api.byId('header');
    	$api.fixIos7Bar(header);
    	
    	address = api.pageParam.address;
    	if(address){
    		$api.html($api.byId('title'),'编辑地址');
    		showAddressInfo();
    	}else{
    		address = {};
    		$api.html($api.byId('title'),'添加地址');
    	}
      	
    }
    
    
    var showAddressInfo = function(){
    	
    	$api.val($api.byId('area'),address.city+'-'+address.province+'-'+address.district)
    	
    	$api.val($api.byId('receiver'), address.receiver);
		$api.val($api.byId('mobile'), address.mobile);
	    $api.val($api.byId('province'), address.province);
	    $api.val($api.byId('city'), address.city);
	    $api.val($api.byId('district'), address.district);
	    
	    $api.val($api.byId('address'), address.address);
	 	$api.val($api.byId('addressId'), address._id);
    	
    }
    
	//添加地址
	 var subAddress = function(){ 
	 	
	 	address.account=member.account;
	 	address.receiver=$api.val($api.byId('receiver'));
	 	address.mobile=$api.val($api.byId('mobile'));
	 	address.address=$api.val($api.byId('address'));
	 	
	 	address.addressId=address._id;
	 	
	 	if(address.receiver==""||address.mobile==""||address.address==""||address.province==""){
	 		     toast('信息不能为空!');
				 return;
	 	}
	 	delete address._id;
	 	do_ajax("/app/member/addressedit",'post',address,function(result,err){
			api.hideProgress();
			if(result.resultCode == '0') {
	 			sendEvent();
	 			api.closeWin();
	 		}else{
	 			 toast(result.datas);
	 		}
	 	});
	}
	
	var selectArea = function(){
		var obj = api.require('citySelector');
		obj.open({
		},function(ret,err){
			address.province = ret.province;
			address.city = ret.city;
			address.district = ret.county;
			$api.val($api.byId('area'),ret.city+'-'+ret.province+'-'+ret.county)
		});

	}
	
	
	//发送地址更新监听事件
	var sendEvent = function(){
		api.sendEvent({
		    name: 'addAddressSuccess',
		    extra: address                              //添加的或者编辑的地址  
		});
	}
	

